home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / findAllIntersections.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  5.7 KB  |  176 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  April 22, 1998
  22. //<doc>
  23. //<name findAllIntersections>
  24. //<owner "Alias|Wavefront Unsupported">
  25. //
  26. //<keywords>
  27. //        curve NURBS intersect
  28. //
  29. //<synopsis>
  30. //    string[] findAllIntersections(string $crvs[], int $numCrvsToIntersect,
  31. //            int $useDir, float $dirX, float $dirY, float $dirZ, 
  32. //            float $tolerance, int $sorted, int $history,
  33. //            string $intersectNodes[] )
  34. //
  35. //<description>
  36. //      Find all intersections between a list of curves, two at a time.
  37. //        If there are no intersections, then no nodes are created.
  38. //
  39. //<flags>
  40. //      string[]    $crvs    List of curves to intersect
  41. //      int            $crvCount    Number of curves on the list
  42. //      int            $useDir    Use the direction for intersection
  43. //      float        $dirX    X Direction for intersection
  44. //      float        $dirY    Y Direction for intersection
  45. //      float        $dirZ    Z Direction for intersection
  46. //      float        $tolerance    Intersection tolerance
  47. //      int            $sorted    Sort the parameter list?
  48. //      int            $history    Remember construction history?
  49. //      string[]    $intersectNodes    List of intersection nodes created
  50. //
  51. //<returns>
  52. //      void :
  53. //
  54. //</doc>
  55.  
  56. //  Description:
  57. //         This proc creates a crv-crv intersection node with two curves
  58. //         and returns the name of the new crv-intersect DN.  Also returns
  59. //         the parameters at which the curves intersect each other.
  60. //        If there are no intersections, then no node is created and
  61. //        nothing is returned.
  62. //
  63. proc string createCrvCrvIntersect( string $crv1, string $crv2,
  64.     int $useDir, float $dirX, float $dirY, float $dirZ,
  65.     float $tolerance,
  66.     float $intersections1[], float $intersections2[] )
  67. {
  68.     // Create the intersect node
  69.     //
  70.     string $intersectNode = `createNode curveIntersect`;
  71.     setAttr ($intersectNode + ".tolerance") $tolerance;
  72.     connectAttr ($crv1 + ".worldSpace") ($intersectNode + ".inputCurve1");
  73.     connectAttr ($crv2 + ".worldSpace") ($intersectNode + ".inputCurve2");
  74.  
  75.     setAttr ($intersectNode + ".useDirection") $useDir;
  76.     setAttr ($intersectNode + ".direction") -type "double3" $dirX $dirY $dirZ;
  77.  
  78.     // Check if there are any intersections.  If not, then delete
  79.     // the node and return nothing.
  80.     //
  81.     $intersections1 = `getAttr ($intersectNode + ".parameter1")`;
  82.     int $numIparms = size($intersections1);
  83.     if( $numIparms == 0 ) {
  84.         delete $intersectNode;
  85.         $intersectNode = "";
  86.     } else {
  87.         $intersections2 = `getAttr ($intersectNode + ".parameter2")`;
  88.     }
  89.     return $intersectNode;
  90. }
  91.  
  92. /////////////////////////////////////////////////////////////////////
  93. //    Description:
  94. //        Takes a list of curves and intersects with a specified number
  95. //        of other curves in the list.
  96. //        
  97. global proc string[] findAllIntersections( 
  98.     string $crvs[], int $numCrvsToIntersect,
  99.     int $useDir, float $dirX, float $dirY, float $dirZ, 
  100.     float $tolerance,
  101.     int $sorted,
  102.     int $history, string $intersectNodes[] )
  103. {
  104.     int $i;
  105.     int $j;
  106.     int $numCrvs = size($crvs) - 1;
  107.     string $parms[];
  108.     for( $i = 0; $i < $numCrvs;  $i ++ ) {
  109.         for( $j = 0; $j < $numCrvsToIntersect; $j ++ ) {
  110.  
  111.             if( ($numCrvs-$j) > $i ) {
  112.                 int $tmp = $numCrvs-$j;
  113.                 // intersect $crvs[$i] with $crvs[$numCrvs-$j]
  114.                 float $intsx1[];
  115.                 float $intsx2[];
  116.                 string $intsx = createCrvCrvIntersect( 
  117.                     $crvs[$i], $crvs[$numCrvs-$j],
  118.                     $useDir, $dirX, $dirY, $dirZ, $tolerance,
  119.                     $intsx1, $intsx2 );
  120.                 int $numIntsx = size($intsx1);
  121.                 if( $numIntsx > 0 ) {
  122.                     // add the parameter into ordered list for $crvs[$i]
  123.                     // and $crvs[$numCrvs-$j]
  124.                     for( $p = 0; $p < $numIntsx; $p ++ ) {
  125.                         $parms[$i] = $parms[$i] + " " + $intsx1[$p];
  126.                         $parms[$numCrvs-$j] = $parms[$numCrvs-$j] + " " + $intsx2[$p];
  127.                         if( $history == 1 ) {
  128.                             $intersectNodes[$i] = $intersectNodes[$i] + 
  129.                                 $intsx + ".p1["+$p+"] ";
  130.                             $intersectNodes[$numCrvs-$j] = 
  131.                                 $intersectNodes[$numCrvs-$j] + $intsx + ".p2["+$p+"] ";
  132.                         }
  133.                     }
  134.                 }
  135.                 if( $history == 0 && (size($intsx1) > 0) ) {
  136.                     delete $intsx;
  137.                 }
  138.                 clear( $intsx1 );
  139.                 clear( $intsx2 );
  140.             }
  141.         }
  142.     }
  143.  
  144.     // Go through the $parms list and sort each one into ascending order
  145.     //
  146.     if( $sorted == 1 ) {
  147.         int $numTokens;
  148.         float $floatParms[];
  149.         float $sortedParms[];
  150.         string $tokens[];
  151.         string $parmsNew;
  152.         for( $i = 0; $i <= $numCrvs;  $i ++ ) {
  153.             $numTokens = 0;
  154.             if( size($parms[$i]) > 0 ) {
  155.                 $numTokens = `tokenize $parms[$i] " " $tokens`;
  156.                 for( $j = 0; $j < $numTokens; $j ++ ) {
  157.                     if( size( $tokens[$j]) > 0 ) {
  158.                         $floatParms[size($floatParms)] = $tokens[$j];
  159.                     }
  160.                 }
  161.             }
  162.             $sortedParms = `sort $floatParms`;
  163.     
  164.             $parmsNew = "";
  165.             for( $j = 0; $j < $numTokens; $j ++ ) {
  166.                 $parmsNew += " ";
  167.                 $parmsNew += $sortedParms[$j];
  168.             }
  169.             $parms[$i] = $parmsNew;
  170.             clear( $floatParms );
  171.             clear( $sortedParms );
  172.         }
  173.     }
  174.     return $parms;
  175. }
  176.